package com.shop.dao.implement;

import java.util.List;

import com.shop.dao.HibernateBaseDao;
import com.shop.dao.IUserDao;
import com.shop.pojo.User;

public class UserDao extends HibernateBaseDao<User> implements IUserDao {
	
	
	@SuppressWarnings("unchecked")
	public User findByUserId(String userid){
		List<User> list=getHibernateTemplate().find("from User where userid=?",userid);
		if(list.isEmpty())return null;
		else return list.get(0); 
		
	}
	@SuppressWarnings("unchecked")
	public List<User> findByLatestOrder(int firstResult,int  maxResult){
		String hql="select distinct  u from User u join u.orders o order by o.time desc";
		return findByHql(hql, null, firstResult, maxResult, null);
		
	}
	public int  count(){
		String hql="select count(*) from User";
		return ((Long)find(hql, null)).intValue();
	}
	@SuppressWarnings("unchecked")
	public List<User> findAll(int firstResult, int maxResult) {
		String hql="from User u order by u.insertTime desc";
		return findByHql(hql, null, firstResult, maxResult, null);
	}

}
